////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include "TestSteeringAI.hpp"

#include <SmegAI\Steering\SteeringManager.hpp>

#include <SmegTools/Debug/DebugNew.hpp>

namespace smeg {
    namespace ai {
        
////////////////////////////////////////////////////////////
/// Default Constructor
////////////////////////////////////////////////////////////
TestSteeringAI::TestSteeringAI() :
    AIEntity(),
    m_fSeekWeight( 0.0f ),
    m_fFleeWeight( 0.0f ),
    m_fPursueWeight( 0.0f ),
    m_fEvadeWeight( 0.0f ),
    m_fWanderWeight( 0.0f ),
    m_fSeekSlowingRadius( 0.0f ),
    m_fWanderDistance( DEFAULT_CIRCLE_DISTANCE ),
    m_fWanderRadius( DEFAULT_CIRCLE_RADIUS ),
    m_pSeekPursueEntity( NULL ),
    m_pFleeEvadeEntity( NULL )
{
}
    
////////////////////////////////////////////////////////////
/// Constructor
////////////////////////////////////////////////////////////
TestSteeringAI::TestSteeringAI( sf::RenderWindow* _pRW,
                        const sf::Vector2f& _Center,
                        const sf::Vector2f& _Velocity,
                        float _fMass,
                        float _fMaxSpeed,
                        float _fAngleDeg,
                        bool _bIsStatic ) :
    AIEntity( _pRW, _Center, _Velocity, _fMass, _fMaxSpeed, _fAngleDeg, _bIsStatic ),
    m_fSeekWeight( 0.0f ),
    m_fFleeWeight( 0.0f ),
    m_fPursueWeight( 0.0f ),
    m_fEvadeWeight( 0.0f ),
    m_fWanderWeight( 0.0f ),
    m_fSeekSlowingRadius( 0.0f ),
    m_fWanderDistance( DEFAULT_CIRCLE_DISTANCE ),
    m_fWanderRadius( DEFAULT_CIRCLE_RADIUS ),
    m_pSeekPursueEntity( NULL ),
    m_pFleeEvadeEntity( NULL )
{
}
    
////////////////////////////////////////////////////////////
/// Constructor with a sprite
////////////////////////////////////////////////////////////
TestSteeringAI::TestSteeringAI( sf::RenderWindow* _pRW,
                        const std::string& _SpriteFilename,
                        const sf::Vector2f& _Center,
                        const sf::Vector2f& _Velocity,
                        float _fMass,
                        float _fMaxSpeed,
                        float _fAngleDeg,
                        bool _bIsStatic ) :
    AIEntity( _pRW, _SpriteFilename, _Center, _Velocity, _fMass, _fMaxSpeed, _fAngleDeg, _bIsStatic ),
    m_fSeekWeight( 0.0f ),
    m_fFleeWeight( 0.0f ),
    m_fPursueWeight( 0.0f ),
    m_fEvadeWeight( 0.0f ),
    m_fWanderWeight( 0.0f ),
    m_fSeekSlowingRadius( 0.0f ),
    m_fWanderDistance( DEFAULT_CIRCLE_DISTANCE ),
    m_fWanderRadius( DEFAULT_CIRCLE_RADIUS ),
    m_pSeekPursueEntity( NULL ),
    m_pFleeEvadeEntity( NULL )
{
}
    
////////////////////////////////////////////////////////////
/// Copy Constructor
////////////////////////////////////////////////////////////
TestSteeringAI::TestSteeringAI( const TestSteeringAI& _Copy ) :
    AIEntity( _Copy ),
    m_fSeekWeight( 0.0f ),
    m_fFleeWeight( 0.0f ),
    m_fPursueWeight( 0.0f ),
    m_fEvadeWeight( 0.0f ),
    m_fWanderWeight( 0.0f ),
    m_fSeekSlowingRadius( 0.0f ),
    m_fWanderDistance( DEFAULT_CIRCLE_DISTANCE ),
    m_fWanderRadius( DEFAULT_CIRCLE_RADIUS ),
    m_pSeekPursueEntity( NULL ),
    m_pFleeEvadeEntity( NULL )
{
}
    
////////////////////////////////////////////////////////////
/// Destructor
////////////////////////////////////////////////////////////
TestSteeringAI::~TestSteeringAI()
{
}

////////////////////////////////////////////////////////////
/// Update the entity
////////////////////////////////////////////////////////////
void TestSteeringAI::Update( float _fDeltaTime ) {    
    m_SteeringManager.Reset();

    if ( m_fSeekWeight > 0.0f && m_pSeekPursueEntity ) {
        m_SteeringManager.Seek( m_pSeekPursueEntity->GetCenter(), m_fSeekSlowingRadius, m_fSeekWeight );
    }
    if ( m_fPursueWeight > 0.0f && m_pSeekPursueEntity ) {
        m_SteeringManager.Pursue( m_pSeekPursueEntity, m_fPursueWeight );
    }
    if ( m_fFleeWeight > 0.0f && m_pFleeEvadeEntity ) {
        m_SteeringManager.Flee( m_pFleeEvadeEntity->GetCenter(), m_fFleeWeight );
    }
    if ( m_fEvadeWeight > 0.0f && m_pFleeEvadeEntity ) {
        m_SteeringManager.Evade( m_pFleeEvadeEntity, m_fEvadeWeight );
    }
    if ( m_fWanderWeight > 0.0f ) {
        m_SteeringManager.Wander( m_fWanderDistance, m_fWanderRadius, m_fWanderWeight );
    }

    AIEntity::Update( _fDeltaTime );
}

/*********************** Behaviors ************************/
void TestSteeringAI::SetSeekWeight( float _fWeight, core::BaseEntity* _pEntity, float _fSlowingRadius ) {
    m_fSeekWeight = _fWeight;
    m_fPursueWeight = 0.0f;

    m_pSeekPursueEntity = _pEntity;
    m_fSeekSlowingRadius = _fSlowingRadius;
}

void TestSteeringAI::SetSeekWeight( float _fWeight ) {
    m_fSeekWeight = _fWeight;
    m_fPursueWeight = 0.0f;
}

void TestSteeringAI::SetSeekSlowingRadius( float _fSlowingRadius ) {
    m_fSeekSlowingRadius = _fSlowingRadius;
}

void TestSteeringAI::SetFleeWeight( float _fWeight, core::BaseEntity* _pEntity ) {
    m_fFleeWeight = _fWeight;
    m_fEvadeWeight = 0.0f;

    m_pFleeEvadeEntity = _pEntity;
}

void TestSteeringAI::SetFleeWeight( float _fWeight ) {
    m_fFleeWeight = _fWeight;
    m_fEvadeWeight = 0.0f;
}

void TestSteeringAI::SetPursueWeight( float _fWeight, core::BaseEntity* _pEntity ) {
    m_fPursueWeight = _fWeight;
    m_fSeekWeight = 0.0f;

    m_pSeekPursueEntity = _pEntity;
}

void TestSteeringAI::SetPursueWeight( float _fWeight ) {
    m_fPursueWeight = _fWeight;
    m_fSeekWeight = 0.0f;
}

void TestSteeringAI::SetEvadeWeight( float _fWeight, core::BaseEntity* _pEntity ) {
    m_fEvadeWeight = _fWeight;
    m_fFleeWeight = 0.0f;

    m_pFleeEvadeEntity = _pEntity;
}

void TestSteeringAI::SetEvadeWeight( float _fWeight ) {
    m_fEvadeWeight = _fWeight;
    m_fFleeWeight = 0.0f;
}

void TestSteeringAI::SetWanderWeight( float _fWeight, float _fWanderDistance, float _fWanderRadius ) {
    m_fWanderWeight = _fWeight;

    m_fWanderDistance = _fWanderDistance;
    m_fWanderRadius = _fWanderRadius;
}

void TestSteeringAI::SetWanderWeight( float _fWeight ) {
    m_fWanderWeight = _fWeight;
}

void TestSteeringAI::SetWanderDistance( float _fWanderDistance ) {
    m_fWanderDistance = _fWanderDistance;
}

void TestSteeringAI::SetWanderRadius( float _fWanderRadius ) {
    m_fWanderRadius = _fWanderRadius;
}

void TestSteeringAI::SetSeekPursueEntity( core::BaseEntity* _pEntity ) {
    m_pSeekPursueEntity = _pEntity;
}

void TestSteeringAI::SetFleeEvadeEntity( core::BaseEntity* _pEntity ) {
    m_pFleeEvadeEntity = _pEntity;
}


    } // namespace ai
} // namespace smeg